﻿using MyHostSwtich.Core;
using MyHostSwtich.Datas.Models;
using System.Windows.Forms;

using WeifenLuo.WinFormsUI.Docking;

namespace MyHostSwtich
{
    public partial class frmConfigList : DockContent, IMdiForm
    {
        public frmConfigList()
        {
            InitializeComponent();
        }

        public IMainForm OwnerParent { get; set; }

        private void frmConfigList_Load(object sender, System.EventArgs e)
        {
            InitForm();
        }

        private void InitForm()
        {

            var root = tvwConfigs.Nodes[0];

            foreach (var kv in CommonRange.Instance.Configs)
            {
                var key = kv.Key;
                var nd = new TreeNode(key)
                {
                    Tag = kv.Value
                };

                root.Nodes.Add(nd);
            }
            root.Expand();
        }

        private void tvwConfigs_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            var nd = e.Node;
            if (nd.Level <= 0) return;

            var item = nd.Tag as ConfigItem;
            OwnerParent?.ViewConfigItem(item);
        }
    }
}
